<?php session_start(); ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
$db_server = "localhost";
$db_name = "chrishsu_membership";
$db_user = "chrishsu_member";
$db_passwd = "membership";

if(!@mysql_connect($db_server, $db_user, $db_passwd))
        die("無法對資料庫連線");

//資料庫連線採UTF8
mysql_query("SET NAMES utf8");

//選擇資料庫
if(!@mysql_select_db($db_name))
        die("無法使用資料庫");
		
$id = $_POST['id'];
$pw = $_POST['pw'];
$pw2 = $_POST['pw2'];
$comment = $_POST['comment'];

if($id != null && $pw != null && $pw2 != null && $pw == $pw2)
{
        //新增資料進資料庫語法
        $sql = "insert into users (userid, passwd, comment, approved) values ('$id', sha1( '$pw' ), '$comment', 0)";
        if(mysql_query($sql))
        {
                echo '新增成功，請靜候審查';
                echo '<meta http-equiv=REFRESH CONTENT=2;url=test_login.html>';
        }
        else
        {
                echo '新增失敗!';
                echo '<meta http-equiv=REFRESH CONTENT=2;url=test_register.html>';
        }
}
else
{
        echo '輸入有誤';
        echo '<meta http-equiv=REFRESH CONTENT=2;url=test_register.html>';
}
?>